# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>
# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Ding Xiao <tinocodfcdsa10@mails.tsinghua.edu.cn>
# Contributor: Firmy <firmianay@gmail.com>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - removed makedepend on pandoc

pkgname=python-pwntools
_pyname=pwntools
pkgver=4.13.0
pkgrel=1
pkgdesc='CTF framework and exploit development library'
url='https://github.com/Gallopsled/pwntools'
arch=('any')
license=('BSD-2-Clause AND GPL-2.0-or-later AND GPL-3.0-or-later AND MIT')
depends=(
  'python'
  'python-capstone'
  'python-colored-traceback'
  'python-dateutil'
  'python-intervaltree'
  'python-mako'
  'python-packaging'
  'python-paramiko'
  'python-pip'
  'python-psutil'
  'python-pyelftools'
  'python-pygments'
  'python-pyserial'
  'python-pysocks'
  'python-requests'
  'python-rpyc'
  'python-six'
  'python-sortedcontainers'
  'python-unicorn'
  'ropgadget'
)
makedepends=(
  'python-build'
  'python-installer'
)
backup=('etc/pwn.conf')
source=(https://github.com/Gallopsled/pwntools/archive/${pkgver}/${pkgname}-${pkgver}.tar.gz
        pwn.conf)
sha256sums=('20c0742b9d15af69ff21c7b89c9a7f211331c0e7fdad57fff4c1cfdf2a7c7d7a'
            '50916e4e45d026422cd6bfe8de50e7246c61b0b1e0007571e7c04a994282fe89')
b2sums=('59a50621135e5e0fd247de37f9367d07155ab370fab5e5985a2e5900451d1d52b5b8362da2c1f59aaea36cfec9414345d2697256a4197fb0d31e90b4e58af45b'
        'cac0a12eea8abd3d2ee21632e7f2281e7e35c2d7839cfbcba83ae5d0e8f427e9cc2462a6d17d187252b99d9dbbb14393b9d5a63996c42043f553e9b66bfe9e07')

build() {
  cd ${_pyname}-${pkgver}
  python -m build --wheel --no-isolation
}

check() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd ${_pyname}-${pkgver}
  python -m installer --destdir=test_dir dist/*.whl

  PYTHONPATH="test_dir/$_site_packages:$PYTHONPATH" PWNLIB_NOTERM=true python -c 'import pwn'
}

package() {
  cd ${_pyname}-${pkgver}
  python -m installer --destdir="${pkgdir}" dist/*.whl
  find "${pkgdir}/usr/bin" -type f ! -name pwn -delete

  install -Dm 644 "${srcdir}/pwn.conf" -t "${pkgdir}/etc"
  install -Dm 644 LICENSE-pwntools.txt -t "${pkgdir}/usr/share/licenses/${pkgname}"

  # https://github.com/Gallopsled/pwntools/issues/2150
  install -d "${pkgdir}/usr/share/doc/"
  mv -v "${pkgdir}/usr/pwntools-doc" "${pkgdir}/usr/share/doc/"

  install -Dm 644 extra/bash_completion.d/pwn -t  "${pkgdir}/usr/share/bash-completion/completions/"
  install -Dm 644 extra/zsh_completion/_pwn -t "${pkgdir}/usr/share/zsh/site-functions/"
}

# vim:set ts=2 sw=2 et:
